import { acceptHMRUpdate, defineStore } from "pinia";

export const useLookupStore = defineStore("lookup", () => {
    /**
     * Current named of the user.
     */
    const list=ref({});
    const whois=ref({});
    const setWhois=(data:any)=>{
        whois.value[data.domain]=data;
    }
    const setList=(data:any)=> {
        if(Array.isArray(data)) {
            data.forEach((item:any)=>{
                if(!list.value[item.name]) {
                    list.value[item.name]=item;
                }
            });
        }else{
            for(const name in data) {
                if(!list.value[name]) {
                    list.value[name]=data[name];
                }
            }
        }

    };
    const remove=(key:string)=>delete list.value[key];
    const clear=()=>list.value={};
    return {
        list,
        setList,
        remove,
        clear,
        whois,
        setWhois,
    };
},{persist:true});

if (import.meta.hot){
    import.meta.hot.accept(acceptHMRUpdate(useLookupStore, import.meta.hot));
}